<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2018/11/29
 * Time: 10:29
 */

namespace app\admin\controller;


use app\admin\validate\loginValidate;
use think\Controller;
use think\facade\Request;
use think\facade\Session;

class Index extends Controller
{

    public function index()
    {
        return $this->fetch('admin/login');
    }

    public function login()
    {
        $post = Request::post();
        $validate = new loginValidate();
        if($validate->batch()->check($post) !== true){
            $str = implode('!',$validate->getError());
            $this->error($str,'/admin');
        }
        Session::set('user',$post['username'],'user_session');
        $this->success('登陆成功','/admin/Product/productList');
    }
    public function quit()
    {
        Session::delete('user','user_session');
        $this->success('退出成功','/admin/Product/productList');
    }
}